package com.ydh.company.service.impl;

import com.ydh.company.pojo.OrderDetails;
import com.ydh.company.pojo.OrderMain;
import com.ydh.company.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Auther 周晓东
 * @Date 2020/5/5
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private RedisTemplate jsonRedisTemplate;

    /**
     * 将订单信息存入Redis
     * 客户ID、商品ID、商品数量、备注、发货仓库
     * @param orderDetails
     */
    @Override
    public void addOrder(OrderDetails orderDetails) {
        /*jsonRedisTemplate.opsForHash()
                .put("购物车:"+orderDetails.getClientId(),
                        orderDetails.getOrderDetailsId(),
                        orderDetails);*/
        //详情单
        jsonRedisTemplate.opsForHash()
                .put("订货单",orderDetails.getOrderDetailsId(),orderDetails);
        //订单主表


        System.out.println("加入购物车成功");
    }

    @Override
    public List<OrderMain> queryOrder(Integer page, Integer persize) {
        Set keys = jsonRedisTemplate.opsForHash().keys("订货单");
        List list = jsonRedisTemplate.opsForHash().multiGet("订货单",keys);
        return list;
    }
}
